package com.lagou.controller;

import com.lagou.dao.Dao;
import com.lagou.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        System.out.println(username);
        Integer id = Integer.valueOf(req.getParameter("id"));
        String sex = req.getParameter("hobby");
        String bir = req.getParameter("bir");
        //System.out.println(username + "----------" + password);
        QueryRunner qr = new QueryRunner();
        Connection con = DruidUtils.getConnection();
        Dao dao = new Dao(qr,con);
        try {
            Object params[] = {id,username,sex,bir};
            for (Object a : params){
                System.out.println(a);
            }
            int insert = dao.insert(params);
            System.out.println(insert);


        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            dao.flash();
           // DruidUtils.close(con);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
